package com.valveinspectionsys.util;

import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.nfc.NfcAdapter;
import android.provider.Settings;
import android.widget.Toast;

public class ActivityStatusUtil {
     private Context context;
    public ActivityStatusUtil(Context context){
	this.context=context;
    }
    
    /**
     * 判断GPS是否存在或开启
     */
    public boolean openGPSSettings() {
	LocationManager alm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
	if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
	    return true;
	}
	Toast.makeText(context, "请开启GPS！", Toast.LENGTH_SHORT).show();
	Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
	context.startActivity(intent); // 此为设置完成后返回到获取界面
	return false;
    }
    
    //检查是否连接网络
        public boolean isNetWork(){
 		boolean b=false;
 		ConnectivityManager manager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
 		if(manager!=null){
 		    NetworkInfo[] info = manager.getAllNetworkInfo();
 	              if (info != null)
 	                  for (int i = 0; i < info.length; i++)
 	                      if (info[i].getState() == NetworkInfo.State.CONNECTED)
 	                      {	                	
 	                          return true;
 	                      }
 		}
 		 Toast.makeText(context, "没有连接网络", Toast.LENGTH_SHORT).show();
 		Intent intent=new Intent(Settings.ACTION_SETTINGS);
 		context.startActivity(intent);
 		 
 		return b;
 		
 	    }
        
        //检查是否打开nfc
       public boolean isOpenNfc(){
         NfcAdapter   nfcAdapter = NfcAdapter.getDefaultAdapter(context);
         if(!nfcAdapter.isEnabled()){
             Toast.makeText(context, "请打开NFC", Toast.LENGTH_SHORT).show();
             Intent intent=new Intent(Settings.ACTION_SETTINGS);
             context.startActivity(intent);
             return false;
         }
     
	    return true;
            
        }
}
